﻿/*
 * 设计模式 - 中介者模式
 * 目的：由中间者来负责对接双方的交互
 * 
 * 
 * 模型；房东 <--> 中介 <--> 房客
 */


//var landload = new User("房东");
//var tenant = new User("房客");

//Mediator mediator = new Mediator();
//mediator.Trade(1000, landload, tenant);








var service = new UserRoleService();
var user=new User();  
var role=new Role();

service.AssignRole(user, role);



//MediatR















Console.ReadKey();

//class User
//{
//    public User(string name)
//    {
//        Name = name;
//    }

//    public string Name { get; }
//    public int Amount { get; set; }
//}

//class Mediator
//{
//    public void Trade(int amount, User user1, User user2)
//    {
//        user1.Amount += amount;
//        user2.Amount -= amount;

//        Console.WriteLine("{0}增加了{1}元，结余：{2}", user1.Name, amount, user1.Amount);
//        Console.WriteLine("{0}减少了{1}元，结余：{2}", user2.Name, amount, user2.Amount);
//    }
//}





class User { }
class Role { }

class UserInRole
{
    public User User { get; set; }
    public Role Role { get; set; }
}

class UserRoleService
{
    public void AssignRole(User user, Role role)
    {
        new UserInRole() { Role = role, User = user };
    }
}